var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), a = require("../../../@babel/runtime/helpers/asyncToGenerator"), e = getApp();

Page({
    data: {
        popupConsignmentShow: !1,
        popupPlatformShow: !1,
        takeGoodsShow: !1,
        name: "",
        goods_name: "",
        page: 1,
        finished: !1,
        listData: [],
        lock: "",
        manage_id: "",
        manage_goods: {},
        timeData: {},
        now: "",
        order_id: "",
        is_sign: !1
    },
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: t.name
        }), this.setData({
            name: t.name,
            now: String(Date.parse(new Date())).substring(0, 10)
        }), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getData();
    },
    getData: function() {
        var t = this;
        if (!this.data.finished) {
            var a = "代销管理" == this.data.name ? "plugin.stock-service.frontend.controllers.help.index" : "我的存货" == this.data.name ? "plugin.stock-service.frontend.controllers.stock.index" : "", n = e.getNetAddresss(a);
            e._getNetWork({
                url: n,
                data: {
                    page: this.data.page,
                    goods_name: this.data.goods_name
                },
                success: function(a) {
                    if (1 !== a.data.result) return wx.showToast({
                        title: a.data.msg
                    }), !1;
                    var e, n = a.data.data, s = !1;
                    t.setData({
                        lock: n.lock,
                        is_sign: n.is_sign
                    }), (0 === n.list.data.length || n.list.data.length < n.list.per_page || n.list.current_page === n.list.last_page) && (s = !0), 
                    e = t.data.listData.concat(n.list.data), t.setData({
                        finished: s,
                        listData: e,
                        page: ++t.data.page
                    });
                }
            });
        }
    },
    sureConsignment: function() {
        var n = this;
        return a(t.default.mark(function a() {
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    n.data.is_sign ? e._getNetWork({
                        url: e.getNetAddresss("plugin.shop-esign.frontend.contract.get-contract"),
                        data: {
                            activity_id: n.data.order_id,
                            plugin_name: "stock-service"
                        },
                        success: function(t) {
                            var a = t.data;
                            1 == t.data.result && (1 === a.data.need_sign && a.data.contract_id ? wx.showModal({
                                title: "提示",
                                content: "代销前需要签署电子合同",
                                showCancel: !1,
                                success: function(t) {
                                    t.confirm && wx.navigateTo({
                                        url: "/packageH/signPage/signPage?id=".concat(a.data.contract_id, "&fromOrder=1")
                                    });
                                }
                            }) : n.asyncConsignment());
                        }
                    }) : n.asyncConsignment();

                  case 1:
                  case "end":
                    return t.stop();
                }
            }, a);
        }))();
    },
    asyncConsignment: function() {
        var t = this, a = e.getNetAddresss("plugin.stock-service.frontend.controllers.stock.help");
        e._getNetWork({
            url: a,
            data: {
                manage_id: this.data.manage_id
            },
            success: function(a) {
                var e = a.data, n = (e.data, e.msg), s = e.result;
                wx.showToast({
                    title: n,
                    icon: "none"
                }), s && (t.setData({
                    popupConsignmentShow: !1,
                    page: 1,
                    finished: !1,
                    listData: []
                }), t.getData());
            }
        });
    },
    openTakeGoodsShow: function(t) {
        this.setData({
            takeGoodsShow: !0,
            manage_goods: t.currentTarget.dataset.item
        });
    },
    openConsignment: function(t) {
        t.currentTarget.dataset.item.help_button && this.setData({
            popupConsignmentShow: !0,
            manage_id: t.currentTarget.dataset.item.id,
            order_id: t.currentTarget.dataset.item.order_id
        });
    },
    closePopupConsignmentShow: function() {
        this.setData({
            popupConsignmentShow: !1
        });
    },
    clickPopupPlatformShow: function(t) {
        t.currentTarget.dataset.item.back_button && this.setData({
            popupPlatformShow: !0,
            manage_id: t.currentTarget.dataset.item.id
        });
    },
    closePopupPlatformShow: function() {
        this.setData({
            popupPlatformShow: !1
        });
    },
    surePlatform: function() {
        var t = this, a = e.getNetAddresss("plugin.stock-service.frontend.controllers.help.back");
        e._getNetWork({
            url: a,
            data: {
                manage_id: this.data.manage_id
            },
            success: function(a) {
                var e = a.data, n = (e.data, e.msg), s = e.result;
                wx.showToast({
                    title: n,
                    icon: "none"
                }), s && (t.setData({
                    popupPlatformShow: !1,
                    page: 1,
                    finished: !1,
                    listData: []
                }), t.getData());
            }
        });
    },
    onSearch: function(t) {
        this.setData({
            goods_name: t.detail,
            page: 1,
            finished: !1,
            listData: []
        }), this.getData();
    },
    finishTime: function(t) {}
});